package panel.viewSpots.navigation
{
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import com.greensock.TweenLite;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	public class NavigationSpot extends Sprite
	{
		private var _nameTxt:TextField;
		private var _iconContainer:Sprite;
		private var _loader:ResourceLoader;
		private var _uri:URI;
		private var _data:Object;
		private var _key:String;
		private var _onPlaySound:Function;
		private var _clickTime:uint;
		private var _lock:Boolean;

		private var _arrow:ArrowItem;
		public function NavigationSpot()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_nameTxt = new TextField();
			_nameTxt.autoSize = "left";
			_nameTxt.mouseEnabled = false;
			_iconContainer = new Sprite();
			this.addChild(_iconContainer);
			this.addChild(_nameTxt);
			
		}
		
		public function shake():void
		{
		
			_iconContainer.rotation = 10;
			var calls:Function = function():void
			{
				
			TweenLite.to(_iconContainer, 1, {rotation:-20,onComplete:callBack});
			}
			var callBack:Function = function():void
			{
				TweenLite.to(_iconContainer, 1, {rotation:20,onComplete:calls});
			}
			calls();
		}
		
		public function stopShake():void
		{
			_iconContainer.rotation = 0;
			TweenLite.killTweensOf(_iconContainer);
		}
		
		public function show(data:Object,loader:ResourceLoader,uri:URI,spotSpr:Sprite):void
		{
			_loader = loader;
			_uri = uri;
			_data = data;
			spotSpr.x = -spotSpr.width/2;
			spotSpr.y = -spotSpr.height/2;
			_iconContainer.addChild(spotSpr);
			this.x = data.posX + spotSpr.width/2;
			this.y = data.posY + spotSpr.height/2;
			TextFieldUtils.setHtmlText(_nameTxt,HtmlText.formatSizeColor(data.name,0xfff100),true,true);
			
			_arrow = new ArrowItem(_loader);
			_arrow.visible = false;
			this.addChild(_arrow);
			resize();
		}
		
		public function changeArrow(isShow:Boolean,index:int):void
		{
			_arrow.visible = isShow;
			_arrow.label = index + "";
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		public function get spotID():String
		{
			return _data.id;
		}
		
		private function resize():void
		{
			_nameTxt.y = _iconContainer.y + _iconContainer.height * 0.5;
			_nameTxt.x = _iconContainer.x + (_iconContainer.width - _nameTxt.width) * 0.5 - _iconContainer.width * 0.5;
			
			_arrow.x = _iconContainer.x - _arrow.width * 0.5;
			_arrow.y = _iconContainer.y - _arrow.height;
		}
		
	}
}